//
//  ZHMacroFunction.swift
//  ZHPageView
//
//  Created by Rango on 2020/8/27.
//  Copyright © 2020 Rango. All rights reserved.
//

import UIKit

struct ZHConstant {
    static var randomColor: UIColor {
        UIColor(red: CGFloat(arc4random_uniform(200)) / 255.0,
                green: CGFloat(arc4random_uniform(200)) / 255.0,
                blue: CGFloat(arc4random_uniform(200)) / 255.0,
                alpha: 1)
    }
    
    static var kScreenBounds: CGRect { UIScreen.main.bounds }
    static var kScreenWidth: CGFloat { kScreenBounds.width }
    static var kScreenHeight: CGFloat { kScreenBounds.height }

    // iOS 13 之前的版本
    static var kStatusBarHeight: CGFloat { UIApplication.shared.statusBarFrame.height }
    static var iPhoneX: Bool { kStatusBarHeight >= 44 }
    
    static func kNavigationBarHeight(_ target: UIViewController? = nil) -> CGFloat {
        if let target = target {
            return target.navigationController?.navigationBar.frame.height ?? 0
        }
        return 44
    }
}

func kScreenBounds() -> CGRect {
    return UIScreen.main.bounds
}
func kScreenWidth() -> CGFloat {
    return kScreenBounds().width
}
func kScreenHeight() -> CGFloat {
    return kScreenBounds().height
}
func kStatusBarHeight() -> CGFloat {
    return UIApplication.shared.statusBarFrame.height
}
func kNavigationBarHeight(_ target: UIViewController? = nil) -> CGFloat {
    if let target = target {
        return target.navigationController?.navigationBar.frame.height ?? 0
    }
    return 44
}
